package com.xiejr.controller;

import com.xiejr.api.interfaces.oss.OssService;
import com.xiejr.cache.DistributedCache;
import com.xiejr.util.RedisUtil;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author mobai
 * @since 2021/2/14 12:05
 */
@RestController
@Api(tags = "缓存接口")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@RequestMapping("redis")
public class RedisController implements DistributedCache {

    private final RedisUtil redisUtil;

    private final OssService ossService;

    @Override
    @PostMapping("/set")
    public void set(@RequestParam("key") String key, @RequestParam("value") Object value) {
        redisUtil.set(key,value);
    }

    @Override
    @PostMapping("/setWithExpire")
    public void set(@RequestParam("key") String key,@RequestParam("value") Object value, @RequestParam("expire") int expire) {
        redisUtil.set(key,value,expire);
    }

    @Override
    @GetMapping("/hasKey")
    public boolean hasKey(@RequestParam("key") String key) {
        return redisUtil.hasKey(key);
    }

    @Override
    @GetMapping("/get")
    public Object get(@RequestParam("key") String key) {
        return redisUtil.get(key);
    }

    @Override
    @GetMapping("/ip")
    public String getIp() {
        return "localhost";
    }

    @GetMapping("test")
    public String test(){
        ossService.upload("1");
        return "111";
    }
}
